<?php

if (!isset($_SESSION)) {
	session_start();
}

require_once 'class/config.php';

class ChooseContent
{	
	private $db;
		
	public function __construct()
	{
		$this->db = DataBase::getInstance();		
	}
	
	function getConclusionData($conclusionString)
	{
		$conclusionData = Array();
		$conclusionArray = explode(',', $conclusionString);
		$conclusionData['place'] = $conclusionArray[0];
		$dateArray = explode('<', $conclusionArray[1]);
		$conclusionData['date'] = $this->strToDate($dateArray[0]);
		return $conclusionData;
	}
	
	function getEFData($eFString)
	{
		$efArray = explode(', ', $eFString);
		$efData = Array();
		$efData['date'] = $this->strToDate($efArray[0]);
		$efData['text'] = $efArray[1];
		return $efData;
	}
	
	function getCountryName($countryNameString)
	{
		$countryNameArray = explode('<', $countryNameString);
		$countryName = $countryNameArray[0];
		return $countryName;
	}
	
	function getCountryIdentifier($countryIdentifiers, $countryName){
		$identifier = 'NONE';
		switch ($countryName){
			case "Bolivia (Plurinational State of)" : $countryName = 'Bolivia';
			break;
			case "Bosnia and Herzegovina" : $countryName = "BOSNIA AND HERZEGOWINA";
			break;
			case "Croatia" : $countryName = "CROATIA (local name: Hrvatska)";
			break;
			case "Democratic People's Republic of Korea" : $countryName = "KOREA, D.P.R.O.";
			break;
			case "Democratic Republic of the Congo" : $countryName = "CONGO";
			break;
			case "Lao People's Democratic Republic" : $countryName = "LAOS ";
			break;
			case "Libya" : $countryName = "LIBYAN ARAB JAMAHIRIYA";
			break;
			case "Myanmar" : $countryName = "MYANMAR (Burma) ";
			break;
			case "Republic of Korea" : $countryName = "KOREA, REPUBLIC OF";
			break;
			case "Republic of Moldova" : $countryName = "MOLDOVA, REPUBLIC OF";
			break;
			case "Slovakia" : $countryName = "SLOVAKIA (Slovak Republic)";
			break;
			case "St. Vincent and the Grenadines" : $countryName = "SAINT VINCENT AND THE GRENADINES";
			break;
			case "The former Yugoslav Republic of Macedonia" : $countryName = "MACEDONIA";
			break;
			case "United Kingdom of Great Britain and Northern Ireland" : $countryName = "UNITED KINGDOM";
			break;
			case "United Republic of Tanzania" : $countryName = "TANZANIA, UNITED REPUBLIC OF";
			break;
			case "United States of America" : $countryName = "UNITED STATES";
			break;
			case "Venezuela (Bolivarian Republic of)" : $countryName = "VENEZUELA";
			break;
			case "Holy See" : $countryName = "HOLY SEE (VATICAN CITY STATE)";
			break;
			case "St. Kitts and Nevis" : $countryName = "SAINT KITTS AND NEVIS";
			break;
			case "St. Lucia" : $countryName = "SAINT LUCIA";
			break;
			case "Timor-Leste" : $countryName = "EAST TIMOR";
			break;
			case "Micronesia (Federated States of)" : $countryName = "MICRONESIA, FEDERATED STATES OF";
			break;
		}
		foreach ($countryIdentifiers as $item){
			if (strtolower($item['countryName']) == strtolower($countryName)){
				$identifier = $item['countryIdentifier'];
				break;
			}
		}
		return $identifier;
	}
	
	function getRegistrationData($registrationString)
	{
		$registrationData = Array();
		$registrationArray = explode(', ', $registrationString);
		$registrationData['date'] = $this->strToDate($registrationArray[0]);
		$registrationNoArray = explode('. ', $registrationArray[1]);
		$registrationData['No'] = $registrationNoArray[1];
		return $registrationData;
	}
	
	function getRatificationData($ratificationString)
	{
		$ratificationData = Array();
		if (isset($ratificationString) && !empty($ratificationString)){
			$ratificationArray = explode(' ', trim(trim($ratificationString), '[]'));
			$ratificationData['date'] = $this->strToDate(implode(' ', array($ratificationArray[0], $ratificationArray[1], $ratificationArray[2])));
			if (isset($ratificationArray[3])) {
				$ratificationData['details'] = $ratificationArray[3];
			} else {
				$ratificationData['details'] = '';
			}
		} else {
			$ratificationData['date'] = '0000-00-00';
			$ratificationData['details'] = '';
		}
		return $ratificationData;
	}
	
	function cleanRatification($ratificationString)
	{
		$ratificationLength = 0;
		$ratificationLength = strlen($ratificationString);
		$firstCharacter = $ratificationString[0];
		$lastCharacter = $ratificationString[$ratificationLength - 1];
		if (preg_match("\W", $lastCharacter)) {
			
		}
	}
	
	function strToDate($string)
	{
		$unixTime = strtotime($string);
		$date = date("Y-m-d",  $unixTime);
		return $date;
	}
}